<template>
  <div>
    <el-table
      :data="arr"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      :tree-props="{ children: 'children' }"
    >
      <el-table-column prop="id" label="编号" sortable width="180">
      </el-table-column>
      <el-table-column prop="title" label="轮播图标题" sortable>
      </el-table-column>
      <el-table-column label="图片">
        <template slot-scope="scope">
          <img :src="$pre + scope.row.img" alt="" />
        </template>
      </el-table-column>
      <el-table-column label="状态"  width="180">
        <template slot-scope="scope">
          <el-button v-if="scope.row.status == 1" type="primary">启用</el-button>
          <el-button v-else type="info">禁用</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="操作" width="180">
        <template slot-scope="scope">
          <el-button type="primary" @click="willUpdate(scope.row.id)">编辑</el-button>
          <el-button type="danger" @click="del(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import { reqbannerdelete } from "../../../http/api";
import { successAlert } from "../../../utils/alert";
export default {
  computed: {
    ...mapGetters({
      arr: "banner/arr"
    }),
  },
  mounted() {
    //一进来就请求
    this.reqArr();
  },
  methods: {
    ...mapActions({
      reqArr: "banner/reqArr",
    }),
    log(s) {
      console.log(s);
    },
    // 5.点了编辑
    willUpdate(id) {
      this.$emit("willUpdate", id);
    },
    // 7.1 点了删除
    del(id) {
      this.$confirm("你确定要删除吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          //删除的请求
          reqbannerdelete({ id: id }).then((res) => {
            if (res.data.code === 200) {
              // 弹成功
              successAlert(res.data.msg);
              // 刷列表
              this.reqArr();
            }
          });
        })
        .catch(() => {});
    },
  },
};
</script>
<style scoped lang="less">
@import "../../../less/index.less";
img {
  width: 50px;
  height: 50px;
}
</style>